//分糖 输入[3,1,4] 输出5
//输入 [3,4,4] 输出4  相邻的两个人饥饿度更高的要更多棒棒糖
function distributeBons(hungers) {
  // write code here
  let result = Array(hungers.length).fill(1);
  for (let i = 1; i < hungers.length; i++) {
    if (hungers[i] > hungers[i - 1]) {
      result[i] = result[i - 1] + 1;
    }
  }
  for (let i = hungers.length - 2; i >= 0; i--) {
    if (hungers[i] > hungers[i + 1]) {
      result[i] = Math.max(result[i], result[i + 1] + 1);
    }
  }
  return result.reduce((a, b) => a + b, 0);
}
console.log(distributeBons([3, 1, 4]));
